import { axios } from '@/utils/request'

const api = {
  resourceList: '/sys/resource/list',
  saveResource: '/sys/resource/save',
  delResource: '/sys/resource/del',
  saveRole: '/sys/role/save',
  listRoleResrouce: '/sys/role/resources',
  roleList: '/sys/role/list',
  roleListAll: '/sys/role/listAll',
  delRole: '/sys/role/del',
  saveUser: '/sys/user/save',
  userList: '/sys/user/list',
  userRoleList: '/sys/user/listRole',
  delUser: '/sys/user/del'
}

export default api
export function getResourceList (parameter) {
  return axios({
    url: api.resourceList,
    method: 'get',
    params: parameter
  })
}

export function saveResource (parameter) {
  return axios({
    url: api.saveResource,
    method: 'post',
    data: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function delResource (parameter) {
  return axios({
    url: api.delResource + '/' + parameter.id,
    method: 'delete',
    data: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getRoleResrouceList (parameter) {
  return axios({
    url: api.listRoleResrouce + '/' + parameter.roleId,
    method: 'get'
  })
}

export function saveRole (parameter) {
  return axios({
    url: api.saveRole,
    method: 'post',
    data: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getRoleList (parameter) {
  return axios({
    url: api.roleList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function roleListAll (parameter) {
  return axios({
    url: api.roleListAll,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function delRole (parameter) {
  return axios({
    url: api.delRole + '/' + parameter.id,
    method: 'delete',
    data: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function saveUser (parameter) {
  return axios({
    url: api.saveUser,
    method: 'post',
    data: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getUserList (parameter) {
  return axios({
    url: api.userList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function delUser (parameter) {
  return axios({
    url: api.delUser + '/' + parameter.id,
    method: 'delete',
    data: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getUserRoleList (parameter) {
  return axios({
    url: api.userRoleList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}
